<?php
/**
 * Created by PhpStorm.
 * User: jacob
 * Date: 18-8-6
 * Time: 下午4:31
 * Logger类
 */
namespace Tiny;

abstract class Log{

  const trace = "trace";
  const debug = "debug";
  const info  = "info";
  const error = "error";
  const fatal = "fatal";
  const warn  = "warn";

  /**
   * @var Log
   */
  protected static $instance = null;
  protected static $isInited = false;

  /**
   * @var Request
   */
  protected $request = null;
  protected $filename;
  protected $methodname;
  protected $line;
  protected $classname;

  public static function setInstance(Log $logger){
    self::$instance = $logger;
  }

  public static function hasInited():bool{
    return self::$isInited;
  }

  public function setRequest(Request $request){
    $this->request = $request;
  }

  abstract static public function getInstance():Log;

  protected function getDate():string {
    return date("Y-m-d H:i:s");
  }


  abstract public static function init();

  abstract public function trace(string $message,\Throwable $throwable = null);
  abstract public function debug(string $message,\Throwable $throwable = null);
  abstract public function info(string $message,\Throwable $throwable = null);
  abstract public function error(string $message,\Throwable $throwable = null);
  abstract public function fatal(string $message,\Throwable $throwable = null);
  abstract public function warn(string $message,\Throwable $throwable = null);

  public function getLocationInformation(){
    $trace = debug_backtrace();//跟踪代码调用
    $prevHop = null;
    return $trace;
  }
}